package com.yq.socket1.day1.practice.test1;



import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.ServerSocket;
import java.net.Socket;

/**
 * @author 3307235355@qq.com
 * @description 客户端键盘录入，服务器端输出文本文件
 * @since 2022/07/01 13:58
 */
public class Server {
    public static void main(String[] args) throws IOException {
        ServerSocket serverSocket = new ServerSocket(8888);
        Socket socket = serverSocket.accept();

        InputStream inputStream = socket.getInputStream();
        FileOutputStream outputStream = new FileOutputStream("shuchu.txt",true);

        byte[] bytes = new byte[1024];
        int read;
        while ((read = inputStream.read(bytes))!=-1){
            // String s = new String(bytes,0,read);d
            outputStream.write(bytes,0,read);
            outputStream.write("\r\n".getBytes());
        }
        System.out.println("保存成功");

        socket.close();
        serverSocket.close();

    }
}
